class Commond{
	constructor(){
		this.servDomain='https://app.diaochan88.com/';
	}
	tips(title){
		uni.showToast({
			title,
			icon:"none"
		});
	}
	http(path,param=null,method="GET",header={}){
		const that=this;
		let headers={
			'content-type': 'application/json',
		}
		
		const token=uni.getStorageSync('token');
		const location=uni.getStorageSync('location');
		if(token)
			headers.token=token;
		return new Promise((resolve,reject)=>{
			// uni.showLoading({
			// 	title:'loading...',
			// 	mask: true
			// });
			uni.request({
				url:`${that.servDomain}${path}`,
				method:method,
				header:Object.assign(headers,header),
				data:param,
				success: (res) => {
					resolve(res.data);
				},fail: (err) => {
					console.log(err);
					uni.showToast({
						icon:"error",
						title:'网络连接失败',
						mask:true,
						duration:1500
					});
					reject(err);
				},complete: () => {
					// uni.hideLoading();
				}
			});
		});
	}
	formatTime(time,fmtStr=0){
		var date =new Date(time * 1000),
			year = date.getFullYear(),
			month = date.getMonth() + 1,
			day = date.getDate(),
			hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
			minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
			second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
			month >= 1 && month <= 9 ? (month = "0" + month) : "";
			day >= 0 && day <= 9 ? (day = "0" + day) : "";
			
			return {year,month,day,hour,minute,second}
	}
	getLocalPos(){
		return new Promise((resolve,reject)=>{
			uni.getLocation({
				type: 'wgs84',
				success: (res) => {
					const location={"lat":res.latitude,"lng":res.longitude};
					resolve(location);
				},
				fail(e) {
					console.log(e);
					reject(e);
				}
			});
		});
	}
}

export default Commond;